--
-- Author: yawei.zhu
-- Date: 2018-10-09 20:31:22
--
-- BossRankController
--

local BossRankView = import("..views.BossRankView")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ControllerBase)

function ClassRef:ctor(data)
    self.super.ctor(self, data)
end

function ClassRef:init()
    self._model = app:getInst("BossModel")
end

function ClassRef:removeListeners()
    self.super.removeListeners(self)
end

function ClassRef:onEvent(eventName, data)
end

function ClassRef:listEvent()
    return {}
end


function ClassRef:openView(data)
    if cc.isDead(self._view) then
        self._view = BossRankView.new(app.mvc.VIEWTYPE_BLUR)
        self._view:onCloseView(handler(self, self.closeView))
        self._view:onClearView(handler(self, self.clearView))
        self._view:onOperate(handler(self, self.onOperate))
        self:addChild(self._view, data)
    end

    self._view:refreshMenuList()
    self._view:show()

    local index = 1 
    if data then index = data end
    self._view:updateView(index)
end
function ClassRef:closeView(data)
    if self._view then
        self:removeChild(self._view, data)
        self:clearView()
    end
end
function ClassRef:clearView()
    if self._view then
        self._view = nil
    end
end

-- 更新小队排名
function ClassRef:onBossTeamRankUpdate(teams)
    self._view:updateTeamRank(teams)
end

-- 更新公会排名
function ClassRef:onBossGuildRankUpdate(guilds)
    self._view:updateGuildRank(guilds)
end 

-------------------------------------------------------


-------------------------------------------------------
function ClassRef:onOperate(op, data)
    print("BossRankController:onOperate op = " .. op)
    if op == "selectedTarget" then
        if data.index == 1 then -- 小队
            self._model:reqWorldBossTeamRank()
        elseif data.index == 2 then -- 公会
            self._model:reqWorldBossGuildRank()
        end
    elseif op == "onHideExtend" then
        self._view:onHideExtend(data)
    elseif op == "onShowExtend" then
        self._view:onShowExtend(data)
    elseif op == "onShowMySelf" then
        self._view:onShowMySelf(data)
    end
end

return ClassRef
